package com.example.demo.controller;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.demo.model.Jingdian;
import com.example.demo.repository.JingdianRepository;

@Controller
@RequestMapping("/jingdian")
public class JingdianController {
	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	JingdianRepository jingdianRepository;
	
	@RequestMapping("/findall")
	@ResponseBody
	@CrossOrigin
	public List<Jingdian> findall(@RequestParam String campus) {
		return jingdianRepository.findByCampus(campus);
	}
	
	@RequestMapping("/find")
	@ResponseBody
	@CrossOrigin
	public List<Jingdian> findByJname(@RequestParam String jname) {
		/**
		 * 此处应只返回一个，但原有程序要求返回数组，以方面页面复用
		 */
		List<Jingdian> jd = new ArrayList<Jingdian>();
		jd.add(jingdianRepository.findByJname(jname));
		return jd;
	}
}
